/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *   02110-1301, USA.
 * 
 * $Id: TitleState.java 46 2008-05-15 18:09:39Z jens464 $
*/
package albareth.frontend.slick.state;


import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import frosch.util.glider.Easing;

import albareth.core.Game;
import albareth.frontend.Resources;
import albareth.frontend.slick.SlickFrontend;
import albareth.frontend.slick.SlickResources;
import albareth.frontend.slick.ui.CharCreationFrame;
import albareth.frontend.slick.ui.GlidingScroll;
import albareth.frontend.slick.ui.UIElement;
import albareth.frontend.slick.ui.UIToolkit;

public class TitleState extends AbstractAlbarethGameState
{
    private UIElement _shownFrame = null;


    
    public TitleState(SlickFrontend frontend)
    {
        super(frontend);
    }

    public int getID()
    {
        return SlickFrontend.STATE_TITLE;
    }

    public void init() throws SlickException
    {
        // TODO Auto-generated method stub
    }
    
    protected void enter() throws SlickException
    {
        removeAllUIElements();
        
        _shownFrame = null;
        if (_frontend.isSoundEnabled()) {
            _frontend.getSound(Resources.SOUND_TITLE_TUNE).loop();
        }
    }
    
    protected void leave() throws SlickException
    {
        _frontend.getSound(Resources.SOUND_TITLE_TUNE).stop();
    }

    public void render(Graphics g) throws SlickException
    {
        Font font = SlickResources.DEFAULT_FONT;
        String text;
        
        g.drawImage(SlickResources.TITLE_BG, 0, 0);
        
        g.setFont(font);
        g.setColor(Color.white);
        text = Game.SUBTITLE.toUpperCase();
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 84);
        
        text = "PRESS MOUSE TO START";
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 360);
        
        
        
        g.setColor(SlickFrontend.DEFAULT_TEXT_COLOR);
        text = "WRITTEN BY JENS ANUTH";
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 517);
        text = "TILE GRAPHIC ART BY DENZI";
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 538);
        text = "(C) 2007-2008 JENS ANUTH";
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 558);
        text = "VERSION: " + Game.VERSION.toUpperCase();
        g.drawString(text, UIToolkit.getCenterStringX(text, SlickFrontend.SCREEN_WIDTH, font), 578);
    }

    public void update(int delta) throws SlickException
    {
    }
    
    private void showCharCreationFrame()
    {
        CharCreationFrame charFrame = new CharCreationFrame(
                GlidingScroll.FROM_LEFT, _frontend
        );
        _shownFrame = charFrame;
        addUIElement(charFrame);
        
    }

    
    public void keyPressedFallthrough(int key, char c)
    {
        if (_shownFrame == null) {
            showCharCreationFrame();
        }
    }

    protected void mouseDownFallthrough(int button, int x, int y)
    {
        if (_shownFrame == null) {
            showCharCreationFrame();
        }
    }


}
